package com.nuit.cxl.bilibili;

import com.nuit.cxl.bilibili.config.JavaConfig;
import com.nuit.cxl.bilibili.service.RecommendService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;

//@SpringBootApplication
public class AnnotationApplication2 {
    public static void main(String[] args) {

//        SpringApplication.run(AnnotationApplication.class, args);
//        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

        ApplicationContext ctx = new AnnotationConfigApplicationContext(JavaConfig.class);

//        RecommendDao recommendDao = (RecommendDao) ctx.getBean(RecommendDao.class);
//        recommendDao.getDataFromDatabase();
        RecommendService recommendService = (RecommendService) ctx.getBean(RecommendService.class);
        recommendService.fetchRecommend();
        RecommendService recommendService2 = (RecommendService) ctx.getBean(RecommendService.class);
        System.out.println("service地址：" + System.identityHashCode(recommendService));
        System.out.println("service2地址：" + System.identityHashCode(recommendService2));


        DataSource dataSource = (DataSource) ctx.getBean(DataSource.class);
        DataSource dataSource2 = (DataSource) ctx.getBean(DataSource.class);
        System.out.println(System.identityHashCode(dataSource));
        System.out.println(System.identityHashCode(dataSource2));
    }

}
